// 条件查询；

const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017';
// const dbName = 'runoob';
const dbName = 'testmgdb';
const colName = 'userinfo';
//连接 
async function getConnect() {
    try {
        let connct = await MongoClient.connect(url, { useNewUrlParser: true });
        return connct;
    } catch (error) {
        throw error;
    }
}

// CRUD

async function exeFun() {
    let connect = await getConnect();
    let coll = connect.db(dbName).collection(colName);
    let data = [{
        'name ': '小向',
        'password': '123456',
        'age': '18'
    }, {
        'name ': '小不不',
        'password': '123456',
        'age': '18'
    }];
    let res = await coll.insertMany(data);
    return res;
}

exeFun().then(res => {
    console.log("insert_res", res);
}).catch(error => {
    console.log(error);
})